from sqlalchemy import Column, Integer, String, DateTime, Text
from datetime import datetime
from .BaseModel import BaseModel

class User(BaseModel):
    __tablename__ = 'users'
    
    id = Column(Integer, primary_key=True, autoincrement=True)
    nickname = Column(String(100), nullable=False, comment='昵称')
    phone = Column(String(20), unique=True, nullable=False, comment='手机号')
    password = Column(String(255), nullable=False, comment='密码')
    created_at = Column(DateTime, default=datetime.now, comment='创建时间')
    
    def __repr__(self):
        return f"<User(id={self.id}, nickname='{self.nickname}', phone='{self.phone}')>"
    
    def to_dict(self):
        return {
            'id': self.id,
            'nickname': self.nickname,
            'phone': self.phone,
            'created_at': self.created_at.isoformat() if self.created_at else None
        }
